package com.shigen.demo.meeting;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class test {

  private static final ExecutorService THREAD_POOL;

  static {
    int processors = Runtime.getRuntime().availableProcessors();
    System.out.println(processors);
    int corePoolSize = processors + 1;
    int maximumPoolSize = processors * 2;
    THREAD_POOL = new ThreadPoolExecutor(corePoolSize,
        maximumPoolSize,
        60L,
        TimeUnit.SECONDS,
        new SynchronousQueue<>(),
        new ThreadFactoryBuilder().setNamePrefix("test-").build(),
        new ThreadPoolExecutor.CallerRunsPolicy()
    );
  }

  public static void main(String[] args) {
    int end = 200;
    int total = 0;
    for (; ; ) {
      int finalI;
      for (int i = 0; i < end; i++) {
        finalI = i;
        int finalI1 = finalI;
        THREAD_POOL.submit(() -> {
          // log.info("index: {} time:{}", finalI1, System.currentTimeMillis());
          // 10s
          // int limit = 10000;
          // try {
          //     Thread.sleep(RandomUtil.randomInt(limit));
          // } catch (InterruptedException e) {
          //     e.printStackTrace();
          // }
        });
      }
    }

  }
}
